﻿using System;
using System.Windows.Controls;
using GalaSoft.MvvmLight.Messaging;

namespace Songhay
{
    using Songhay.Models;

    /// <summary>
    /// Utilities for <see cref="System.Windows.Controls.UserControl"/>.
    /// </summary>
    public static class UserControlUtiltity
    {
        /// <summary>
        /// Converts the <see cref="Func&lt;System.Windows.Controls.UserControl&gt;"/> into a lazy display item.
        /// </summary>
        /// <param name="lazyFunction">The lazy function.</param>
        /// <param name="name">The name.</param>
        /// <param name="displayName">The display name.</param>
        /// <returns></returns>
        public static LazyDisplayItem<UserControl> GetLazyDisplayItem(Func<UserControl> lazyFunction, string name, string displayName)
        {
            var item = new LazyDisplayItem<UserControl>
            {
                DisplayName = displayName,
                LazyItem = new Lazy<UserControl>(lazyFunction),
                Name = name
            };

            return item;
        }

        /// <summary>
        /// Converts the <see cref="Func&lt;System.Windows.Controls.UserControl&gt;"/> into a lazy display item message.
        /// </summary>
        /// <param name="lazyFunction">The lazy function.</param>
        /// <param name="name">The name.</param>
        /// <param name="displayName">The display name.</param>
        public static void SendLazyDisplayItemMessage(Func<UserControl> lazyFunction, string name, string displayName)
        {
            var message = GetLazyDisplayItem(lazyFunction, name, displayName);
            Messenger.Default.Send(message);
        }
    }
}
